export function parseQuery() {
    let res:{ [key: string]: any} = {}

    // #ifdef H5
    const query = (location.href.split('?')[1] || '').trim().replace(/^(\?|#|&)/, '')

    if (!query) {
        return res
    }

    query.split('&').forEach(param => {
        const parts: string[] = param.replace(/\+/g, ' ').split('=')
        if(parts?.length) {
            // @ts-ignore
            const key = decodeURIComponent(parts.shift())
            const val = parts.length > 0 ? decodeURIComponent(parts.join('=')) : null

            if (res[key] === undefined) {
                res[key] = val
            } else if (Array.isArray(res[key])) {
                res[key].push(val)
            } else {
                res[key] = [res[key], val]
            }
        }
    })
    // #endif
    // #ifndef H5
    const pages = getCurrentPages() //获取加载的页面
    const currentPage = pages[pages.length - 1] //获取当前页面的对象
    const url = currentPage.route //当前页面url
    res = currentPage.options //如果要获取url中所带的参数可以查看options
    // #endif
    return res
}
